/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <iostream>
#include <algorithm>
#include <deque>
#include <list>
#include <cstdlib>
#include <ctime>
using namespace std;
bool checkEven(int elem,bool isEven)
{
    if (isEven)
    {
        return elem%2==0;
    }
    else
    {
        return elem%2==1;
    }
}
void show(auto &container)
{
    for(auto element:container)
    {
        cout << element << " ";
    }
    cout << endl;
}
void search_all(auto &sequence,auto &subsequence)
{
    auto iter=search(sequence.begin(),sequence.end(),subsequence.begin(),subsequence.end());
    if (iter!=sequence.end())
    {
        do
        {
            cout << "search a sub-sequence in the sequence,which is at "<<distance(sequence.begin(),iter) << endl;
            ++iter;
        }
        while ((iter=search(iter,sequence.end(),subsequence.begin(),subsequence.end()))!=sequence.end());
    }
    else
    {
        cout << "There isn't a sub-sequence in the sequence" << endl;
    }
}
int main_29()
{
    srand((unsigned int)time(nullptr));
    deque<int> int_deq;
    list<int> int_list;
    int random_int;
    for (int i=0; i<40 ; ++i )
    {
        random_int=rand()%10;
        int_deq.push_back(random_int);
    }
    for (int i=0; i<2 ; ++i )
    {
        random_int=rand()%10;
        int_list.push_back(random_int);
    }
    show(int_deq);
    show(int_list);
    search_all(int_deq,int_list);
    auto iter=find_end(int_deq.begin(),int_deq.end(),int_list.begin(),int_list.end());
    if (iter!=int_deq.end())
    {
        cout << "search a sub-sequence in the sequence,which is at "<<distance(int_deq.begin(),iter) << endl;
    }
    else
    {
        cout << "There isn't a sub-sequence in the sequence" << endl;
    }
    bool bool_arr[]={false,true,false};//odd even odd
    iter=search(int_deq.begin(),int_deq.end(),bool_arr,bool_arr+3,checkEven);
    if (iter!=int_deq.end())
    {
        cout << "search a consecutive odd even odd subsequence in the sequence,which is at "<<distance(int_deq.begin(),iter) << endl;
    }
    else
    {
        cout << "There isn't a subsequence in the sequence" << endl;
    }
    return 0;
}
